﻿using System;
using System.Collections.Generic;
using System.Text;
using Kitware.VTK;

namespace Fu3DEngine
{
    public class PolygonNode : CPNodeBase 
    {
      CPPoly m_ent;
      public PolygonNode(CPPoly ent,string id ):base(id)
      {

          m_ent = ent;
 
      }

      public override void Run()
      {
          base.Run();


      }

      public override void ReLoad()
      {
          throw new NotImplementedException();
      }

      public void CreatePoly(CPPoly cy)
      {
          vtkPoints points = new vtkPoints();
          int id = 0;

          double[] dOrg = new double[3];

          foreach (DPoint dp in cy.m_points)
          {


              points.InsertPoint(id, dp.x, dp.y, 0);

              id++;


          }



          vtkCellArray polyarray = new vtkCellArray();
          polyarray.InsertNextCell(cy.m_points.Count);
          for (int i = 0; i < cy.m_points.Count; i++)
          {
              polyarray.InsertCellPoint(i);
          }

          vtkPolyData polyData = new vtkPolyData();
          polyData.SetPoints(points);
          polyData.SetPolys(polyarray);
          double[] cen1 = polyData.GetCenter();



          //上边这个竟然调试有错，不明白是版本bug,还是参数错误

          //vtk.vtkPLinearExtrusionFilter extrusion = new vtk.vtkPLinearExtrusionFilter();
          //extrusion.SetInput(polyData);
          //extrusion.SetScaleFactor(state.GetHeightFromMeter(this.thickness));

          vtkLinearExtrusionFilter efilter = new vtkLinearExtrusionFilter();
          efilter.SetInput(polyData);
          efilter.SetScaleFactor(cy.height);









      
          m_Poly.m_Mapper.SetInput(efilter.GetOutput());








         

         




          //actor.SetPosition(cy.x, cy.y, cy.z);

          m_Poly.m_Actor.SetPosition(0, 0, cy.z);

          m_Poly.m_Actor.GetProperty().SetAmbientColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);
          m_Poly.m_Actor.GetProperty().SetDiffuseColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);



          this.SParent.m_vtkRenderer.AddActor(m_Poly.m_Actor);


      }
    }
}
